﻿function WebSQLDatabase(options) {
    this.options = options;
    var name = this.options["name"] || "dbname";
    var version = this.options["version"] || "1.0";
    var desc = this.options["desc"] || "我的数据库描述";
    var size = this.options["size"] || 20000;
    this.DB = window.openDatabase(name, version, desc, size, function () {
        if (!this.DB) {
            throw "create database is failed";
        }
    });
}
WebSQLDatabase.prototype = {
    DB: null,
    execute: function (sql, parameters, success, error) {
        this.DB.transaction(function (tx) {
            tx.executeSql(sql, parameters,
            function (tx, result) {
                if (success) {
                    success(result);
                }
            }, function (tx, error) {
                if (error) {
                    error(error);
                }
            })
        })
    },
    createTable: function (tableName, tableField) {
        this.execute("CREATE TABLE IF NOT EXISTS " + tableName + "(" + tableField + ")");
    },
    delTable: function (tableName) {
        this.execute("DROP TABLE " + tableName);
    }
}